home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / MCASM.RAR / MC_ASM.EXE / WROX_ASM / CH12 / GRAPH / TESTGR.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-16  |  2.4 KB  |  136 lines

  1. // Here is a simple test of the graphics system
  2. // Written by Yuri Kiselev, 1994.
  3.  
  4. #pragma -ml
  5.  
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <dos.h>
  9. #include <conio.h>
  10. #include <mem.h>
  11. #include <alloc.h>
  12.  
  13. #include "graph.h"
  14.  
  15. void pixelplay(BYTE colors)
  16. {
  17. do {
  18.     putpixel(random(getmaxx()),random(getmaxy()),random(colors));
  19. } while (!kbhit());
  20. getch();
  21. }
  22.  
  23. void lineplay(BYTE colors)
  24. {
  25. do {
  26.     setcolor(random(colors));
  27.     line(random(getmaxx()),random(getmaxy()),
  28.             random(getmaxx()),random(getmaxy()));
  29.  
  30. } while (!kbhit());
  31. getch();
  32. }
  33.  
  34. void barplay(BYTE colors) //Draw random bars on the screen
  35. {
  36. int maxheight,maxwidth,x,y,x1,y1;
  37. maxwidth = getmaxx();
  38. maxheight = getmaxy();
  39. do {
  40.     setfillstyle(random(11),random(colors));
  41.     x = random(maxwidth);
  42.     y = random(maxheight);
  43.     x1 = random(maxwidth);
  44.     y1 = random(maxheight);
  45.     if (x > x1)
  46.     asm {
  47.         mov ax,x
  48.         xchg ax,x1
  49.         mov x,ax
  50.     }
  51.     if (y > y1)
  52.     asm {
  53.         mov ax,y
  54.         xchg ax,y1
  55.         mov y,ax
  56.     }
  57.     bar(x,y,x1,y1);
  58. } while (!kbhit());
  59. getch();
  60. }
  61.  
  62. void polyplay(BYTE colors)
  63. {
  64. pointtype poly[20];
  65. int maxpts = 5;
  66. int i;
  67. do {
  68.     setfillstyle(random(11),random(colors));
  69.     setcolor(random(colors));
  70.     for(i=0;i<maxpts;i++)
  71.     {
  72.         poly[i].x = random(getmaxx());
  73.         poly[i].y = random(getmaxy());
  74.     }
  75.     poly[maxpts].x = poly[0].x;
  76.     poly[maxpts].y = poly[0].y;
  77.     fillpoly(maxpts+1,poly);
  78. } while (!kbhit());
  79. getch();
  80. }
  81.  
  82. void imageplay(void)
  83. {
  84. int sizex = 80,sizey = 100;
  85. int x,y,x1,y1;
  86. void* savebuffer,*imagebuffer;
  87. setfillstyle(8,2);
  88. bar(0,0,getmaxx(),getmaxy());
  89. setfillstyle(2,12);
  90. bar(0,0,sizex,sizey);
  91. imagebuffer = malloc(64000);
  92. savebuffer = malloc(64000);
  93. getimage(0,0,sizex,sizey,imagebuffer);
  94. do {
  95.     x = random(getmaxx());
  96.     y = random(getmaxy());
  97.     getimage(x,y,x+sizex,y+sizey,savebuffer);
  98.     putimage(x,y,imagebuffer);
  99.     delay(100);
  100.     putimage(x,y,savebuffer);
  101. } while (!kbhit());
  102. getch();
  103. free(savebuffer);
  104. free(imagebuffer);
  105. }
  106.  
  107. int poly[10] = {10,10,40,12,45,39,9,41,10,10};
  108. void main(void)
  109. {
  110. randomize();
  111. if (graphinit() < 0) {printf("Graphics not initialize."); exit(1);}
  112.  
  113. // 16 colors video mode
  114. pixelplay(15);
  115. lineplay(15);
  116. barplay(15);
  117. polyplay(15);
  118. imageplay();
  119.  
  120. // 320x200x256 video mode
  121. switchmode(VGA256);
  122. pixelplay(255);
  123. lineplay(255);
  124. barplay(255);
  125. polyplay(255);
  126. imageplay();
  127.  
  128. // 640x480x256 video mode
  129. switchmode(SVGA640x480x256);
  130. pixelplay(255);
  131. lineplay(255);
  132. barplay(255);
  133. polyplay(255);
  134. imageplay();
  135. closegraph();
  136. }